#!/bin/bash

pushd `dirname $0` > /dev/null
OUTCODE=`pwd`/code.tex
OUTTEST=`pwd`/test.tex
echo -n > $OUTCODE
echo -n > $OUTTEST
pushd ../../ > /dev/null

echo "Generating main source files"

for f in $( ls src/pig src/*.cc src/*.h src/*.sh src/grammar/*lpp src/grammar/*ypp )
do
  echo $f
  echo "\lstset{language=C++}" >> $OUTCODE
  echo "\begin{lstlisting}[caption=`basename $f`]" >> $OUTCODE
  cat $f >> $OUTCODE
  echo "\end{lstlisting}" >> $OUTCODE
  echo >> $OUTCODE
done

echo "Generating test scripts"

for f in $( ls tests/*.cc tests/*.sh )
do
  echo $f
  echo "\lstset{language=C++}" >> $OUTTEST
  echo "\begin{lstlisting}[caption=`basename $f`]" >> $OUTTEST
  cat $f >> $OUTTEST
  echo "\end{lstlisting}" >> $OUTTEST
  echo >> $OUTTEST
done
